<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>冒泡排序</title>
  </head>
  <body></body>
  <script>
    var arr = [1, 5, 9, 7, 3, 4, 6, 8, 2];
    function arrP(arr) {
      for (var i = arr.length - 1; i > 0; i--) {
        for (var k = 0; k < i; k++) {
          if (arr[k] > arr[k + 1]) {
            var ls;
            ls = arr[k];
            arr[k] = arr[k + 1];
            arr[k + 1] = ls;
          }
        }
      }
      return arr;
    }
    console.log(arrP(arr));
  </script>
</html>
